package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.PersonalScoreList;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.utils.MyUtils;
import java.util.List;

public class PersonalScoreListAdapter extends ArrayAdapter<PersonalScoreList.PersonalScoreContent> {
  /* 区分是个人积分  还是分派积分  */
  public static final String EXTRA_TYPE =
      "com.isunland.managesystem.adapter.PersonalScoreListAdapter.EXTRA_TYPE";
  public static final String PERSONAL = "personal";
  public static final String ASSIGN = "assign";
  public static final String APPROVAL = "approval";
  private String type;

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2017-04-17 10:15:59 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvPlanStatus;
    public final TextView tvContentRewards;
    public final TextView tvRewardScore;
    public final TextView tvPunishmentScore;
    public final TextView tvPersonName;
    public final TextView tvPayStaff;
    public final TextView tvInStaff;
    public final LinearLayout llStaffName;

    private ViewHolder(LinearLayout rootView, TextView tvPlanStatus, TextView tvContentRewards,
        TextView tvRewardScore, TextView tvPunishmentScore, TextView tvPersonName,
        TextView tvPayStaff, TextView tvInStaff, LinearLayout llStaffName) {
      this.rootView = rootView;
      this.tvPlanStatus = tvPlanStatus;
      this.tvContentRewards = tvContentRewards;
      this.tvRewardScore = tvRewardScore;
      this.tvPunishmentScore = tvPunishmentScore;
      this.tvPersonName = tvPersonName;
      this.tvPayStaff = tvPayStaff;
      this.tvInStaff = tvInStaff;
      this.llStaffName = llStaffName;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvPlanStatus = (TextView) rootView.findViewById(R.id.tv_planStatus);
      TextView tvContentRewards = (TextView) rootView.findViewById(R.id.tv_content_rewards);
      TextView tvRewardScore = (TextView) rootView.findViewById(R.id.tv_reward_score);
      TextView tvPunishmentScore = (TextView) rootView.findViewById(R.id.tv_punishment_score);
      TextView tvPersonName = (TextView) rootView.findViewById(R.id.tv_person_name);

      TextView tvPayStaff = (TextView) rootView.findViewById(R.id.tv_payStaff);
      TextView tvInStaff = (TextView) rootView.findViewById(R.id.tv_inStaff);
      LinearLayout llStaffName = (LinearLayout) rootView.findViewById(R.id.ll_staffName);
      return new ViewHolder(rootView, tvPlanStatus, tvContentRewards, tvRewardScore,
          tvPunishmentScore, tvPersonName, tvPayStaff, tvInStaff, llStaffName);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_person_score, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    PersonalScoreList.PersonalScoreContent item = getItem(position);
    vh.tvInStaff.setText(MyStringUtil.connect("派予：", item.getInStaffName())); // 被奖惩职员
    vh.tvPayStaff.setText(MyStringUtil.connect("来源：", item.getPayStaffName())); // 奖惩职员
    vh.tvContentRewards.setText(item.getRemark());// 奖惩内容
    vh.tvRewardScore.setText(getContext().getString(R.string.scoresAddNew, item.getRewValue()));//加分
    vh.tvPersonName.setText(
        getContext().getString(R.string.scoresPlusNew, item.getPunValue()));// 减分
    MyUtils.switchShadowStutus(getContext(), vh.tvPlanStatus, item.getDataStatus());

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors

  public PersonalScoreListAdapter(Context context,
      List<PersonalScoreList.PersonalScoreContent> objects, String type) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.type = type;
  }

  @Override public boolean isEmpty() {
    return type.equals(APPROVAL) && super.isEmpty();
  }
}

